package com.chenbei.schedule.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.chenbei.common.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Schema(description = "调度任务")
@TableName("sys_schedule_job")
@Data
public class ScheduleJob extends BaseEntity {

    @Schema(description = "主键ID")
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    @Schema(description = "任务名称")
    @NotBlank(message = "名称不能为空")
    private String name;

    @Schema(description = "群组名称")
    @NotBlank(message = "群组名称不能为空")
    private String groupName = "DEFAULT";

    @Schema(description = "调用方法(例如: bean.method()|xxx.xxx.xxx.method())")
    @TableField("invoke_target")
    @NotBlank(message = "调用方法")
    private String invokeMethod;

    @Schema(description = "调用方法实参集合")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> invokeMethodParams;

    @Schema(description = "cron表达式")
    @TableField("cron_express")
    @NotBlank(message = "cron表达式不能为空")
    private String cronExpress;

    @Schema(description = "任务描述")
    private String description;

    @Schema(description = "上次执行时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("last_execute_time")
    private LocalDateTime lastExecuteTime;

    @Schema(description = "上次执行状态[0:失败|1:成功]")
    @TableField("latest_execute_status")
    private Integer latestExecuteStatus;

    @Schema(description = "下次执行时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("next_execute_time")
    private LocalDateTime nextExecuteTime;

    @Schema(description = "状态[0:禁用|1:启用]")
    private Integer status;

    @Schema(description = "是否并发[0:否|1:是]")
    @TableField("is_concurrent")
    private Integer isConcurrent;
}
